package com.test.daily.leetcode.y2022.m07.day0718.v02;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/18 下午 04:01
 * @version: 1.0
 */
public class Solution {
    public static class Node{
        public int value;
        public Node left;
        public Node right;
        public Node(int value){
            this.value = value;
        }
    }

    public void printTree(Node head){
        print(head, 17, "H", 17);
    }

    public void print(Node node, int height, String to, int len){
        print(node.right, height+1, "v", len);
        String value = to + node.value + to;
        int leftLen = (len - value.length())/2;
        int rightLen = len - leftLen - value.length();
        String leftSpace = getSpace(leftLen);
        String rightSpace = getSpace(rightLen);
        String val = leftSpace + value + rightSpace;
        System.out.println(height*len + val);
        print(node.left, height+1, "^", len);
    }

    public String  getSpace(int num){
        char space = ' ';
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < num; i++) {
            stringBuilder.append(space);
        }
        return stringBuilder.toString();
    }

}
